<style lang="less">
    .title-text span {
        display: block;
        position: relative;
        color: black;
        font-weight: bold;
        text-align: center;
    }
    .title-text span:before, .title-text span:after {
        content: '';
        position: absolute;
        top: 50%;
        background: #dfdfdf;
        width: 44%;
        height: 1px;
    }
    .title-text span:before {
        left: 0;
    }
    .title-text span:after {
        right: 0;
    }
</style>
<template >
    <div style="background-color: rgb(255,255,255)">
        <Row style="margin-top: 1%;">
            <i-col span="18">
                <Button  size="large"  type="primary" style=" float: left;margin-right:24px;">审核页面</Button>
                <Button @click="showPhote" size="large"  type="primary" style=" float: left;">影像资料</Button>
            </i-col>
        </Row>
        <div class="addInfo" style="display: block" >
            <h2 class="title-text" style="text-align: center"><span >审核意见</span></h2>
            <Row style="margin-top: 1%;border: 1px solid #dcdee2; border-color: #e8eaec;    margin: 8px;">
                <Form ref="companyForm" :model="companyForm" :rules="companyFormValidate"  :label-width="160">
                    <Row style="padding-top: 11px">
                        <i-col span="12">
                            <FormItem label="审核意见" prop="status"  style="margin-left: 40%" >
                                <Select v-model="companyForm.status" filterable  style="    width: 200px;" size="default">
                                    <Option v-for="item in statusList" :value="item.value" :key="item.value">{{ item.title }}</Option>
                                </Select>
                            </FormItem>
                        </i-col>
                        <i-col span="6">
                            <Button @click="closeThisTag" size="large"  type="primary" style=" float: right;">返回</Button>
                            <Button @click="Commit('companyForm')" size="large" type="primary" style=" float: right;margin-right:24px;">提交</Button>
                        </i-col>
                    </Row>
                    <Row>
                        <i-col span="12">
                            <FormItem label="备注" prop="examineRemark"  style="margin-left: 40%">
                                <Input type="text" size="default"   v-model="companyForm.examineRemark" clearable  placeholder="请输入" style="width: 400px"/>
                            </FormItem>
                        </i-col>

                    </Row>
                    <Row>
                        <i-col span="12">
                            <FormItem label="退回原因" prop="examineReason"   style="margin-left: 40%">
                                <Input type="text" size="default"   v-model="companyForm.examineReason" clearable  placeholder="请输入原因" style="width: 400px"/>
                            </FormItem>
                        </i-col>

                    </Row>

            <h2 class="title-text"><span id="companyType">第三方公司</span></h2>
                <Row>
                    <i-col span="8">
                        <Form-item label="合作商名称" prop="channelId">
                            <Select v-model="companyForm.channelId" disabled  clearable style="width: 200px;" size="default" >
                                <Option v-for="item in baseInfo"  :value='item.id' :key="item.id">{{ item.channelFullName }}
                                </Option>
                            </Select>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="挂靠公司名称" prop="affiliatedName">
                            <Input type="text" size="default" v-bind:disabled="disabled" v-model="companyForm.affiliatedName" clearable placeholder="请输入"
                                   style="width: 200px" />
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="统一社会信用代码" prop="socUniCrtCode">
                            <Input type="text" size="default" v-bind:disabled="disabled" v-model="companyForm.socUniCrtCode" clearable placeholder="请输入"
                                   style="width: 200px" />
                        </Form-item>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <Form-item label="是否有道路运输许可证" :label-width="200" prop="whetherLicence">
                            <RadioGroup v-model="companyForm.whetherLicence" v-bind:disabled="disabled" size="default">
                                <Radio v-bind:disabled="disabled" label="1">是</Radio>
                                <Radio v-bind:disabled="disabled" label="0">否</Radio>
                            </RadioGroup>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="道路运输许可证有效期至" prop="transPermitValidity">
                            <i-col span="12">
                                <Date-picker  type="date" v-bind:disabled="disabled" size="default"  v-model="companyForm.transPermitValidity"  placeholder="选择日期" style="width: 200px"></Date-picker>
                            </i-col>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="成立时间" prop="foundedTime">
                            <i-col span="12">
                                <Date-picker type="date" v-bind:disabled="disabled" size="default" class="found_time" v-model="companyForm.foundedTime"  placeholder="选择日期" style="width: 200px"></Date-picker>
                            </i-col>
                        </Form-item>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <Form-item label="法定代表人姓名" prop="legalPersonName">
                            <Input type="text" v-bind:disabled="disabled" size="default" v-model="companyForm.legalPersonName" clearable placeholder="请输入"
                                   style="width: 200px" />
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="法人联系方式" prop="legalPersonTel">
                            <Input type="text" v-bind:disabled="disabled" size="default" v-model="companyForm.legalPersonTel" clearable placeholder="请输入"
                                   style="width: 200px" />
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="法人身份证号码" prop="legalPersonIdcard">
                            <Input type="text" v-bind:disabled="disabled" size="default" v-model="companyForm.legalPersonIdcard" clearable placeholder="请输入"
                                   style="width: 200px" />
                        </Form-item>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <Form-item
                            label="营业期限至"
                            prop="oprTermValidity"
                        >
                            <Date-picker
                                v-bind:disabled="disabled"
                                type="date"
                                size="default"
                                v-model="companyForm.oprTermValidity"
                                placeholder="选择日期"
                                style="width: 200px"></Date-picker>
                            <Checkbox v-bind:disabled="disabled"  v-model="companyForm.longTermOrNot">长期</Checkbox>

                        </Form-item>

                    </i-col>
                    <i-col span="8">
                        <Form-item label="已运营年限" prop="operationYears">
                            <Input type="text" id="operation_year" v-bind:disabled="disabled" size="default" v-model="companyForm.operationYears" clearable placeholder="请输入"
                                   style="width: 200px" />
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="注册资本" prop="registeredCapital">
                            <Input type="text" size="default" v-bind:disabled="disabled" v-model="companyForm.registeredCapital" clearable placeholder="请输入"
                                   style="width: 200px" />
                        </Form-item>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <FormItem label="注册省市" prop="domicLocation">
                            <Cascader :data="location" v-bind:disabled="disabled" v-model="companyForm.domicLocation" style="width:200px;" size="default"
                                      :load-data="loadData"></Cascader>
                        </FormItem>
                    </i-col>
                    <i-col span="8">
                        <form-item label="详细地址" prop="registeredAddress">
                            <Input  v-bind:disabled="disabled"  v-model="companyForm.registeredAddress" size="default" style="width: 200px" placeholder="请输入" />
                        </form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="备案有效期至" prop="validityTime">
                            <i-col span="12">
                                <Date-picker  v-bind:disabled="disabled" type="date" size="default"  v-model="companyForm.termValidity"  placeholder="选择日期" style="width: 200px"></Date-picker>
                            </i-col>
                        </Form-item>
                    </i-col>

                </Row>
                <Row>
                    <i-col span="8">
                        <Form-item label="自有运营车辆数" prop="operateVehicles">
                            <Input type="text" v-bind:disabled="disabled"  size="default" v-model="companyForm.operateVehicles" clearable placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="经营状态" prop="operateStatus">
                            <Select v-model="companyForm.operateStatus" v-bind:disabled="disabled" placeholder="请选择" clearable style="    width: 200px;" size="default" >
                                <Option v-for="item in operateStatusList" :value="item.value" :key="item.value">{{ item.title }}
                                </Option>
                            </Select>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <FormItem label="申请时间" >
                            <Date-picker type="date" disabled v-model="companyForm.applyTime" size="default"  style="width: 200px"></Date-picker>
                        </FormItem>
                    </i-col>
                </Row>
                <Row>
                    <i-col span="8">
                        <Form-item label="月单申请数" prop="monthlyApplicationNum">
                            <Input type="text"   size="default" v-model="companyForm.monthlyApplicationNum" clearable placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="总单申请数" prop="totalApplicationNum">
                            <Input type="text"   size="default" v-model="companyForm.totalApplicationNum" clearable placeholder="请输入"
                                   style="width: 200px"/>
                        </Form-item>
                    </i-col>
                    <i-col span="8">
                        <Form-item label="是否在库" :label-width="200" prop="isOrNo">
                            <Checkbox v-bind:disabled="disabled"  v-model="isOrNo" value="false"></Checkbox>
                        </Form-item>
                    </i-col>
                </Row>
            </Form>
            </Row>
        </div>
    </div>
</template>
<script>
    import {examineThirdOrNetCar,examineNewThirdOrNetCar,saveThirdOrNetCar} from "@/projects/afs-apply/api/affiliation/examineThirdOrNetCar";
    import {getAffiliationInfo} from "@/projects/afs-apply/api/affiliation/affiliationAddEdit";
    import { getChannelBaseInfo,getChannelId } from "@/projects/afs-apply/api/register-mng/listRecord";
    import {getLocation} from "_p/afs-apply/api/apply-report/personal/common";
    import { getDictDataByType } from "@/projects/basic/api/admin/datadic";
    export default {
        data() {
            // const validateExamineReason = (rule, value, callback) => {
            //     if (value=="03") {
            //         this.companyFormValidate.monthlyApplicationNum[0].required=false;
            //         this.companyFormValidate.monthlyApplicationNum[1].required=false;
            //         this.companyFormValidate.totalApplicationNum[0].required=false;
            //         this.companyFormValidate.totalApplicationNum[1].required=false;
            //     }else if(value == "04"){
            //         this.companyFormValidate.monthlyApplicationNum[0].required=false;
            //         this.companyFormValidate.monthlyApplicationNum[1].required=false;
            //         this.companyFormValidate.totalApplicationNum[0].required=false;
            //         this.companyFormValidate.totalApplicationNum[1].required=false;
            //     } else {
            //         callback();
            //     }
            // };
            const isPositiveInteger = (rule, value, callback) => {
                var reg = /^[0-9]+[0-9]*[0-9]*$/;
                if (!reg.test(value)) {
                    callback(new Error("请输入正整数"));
                } else {
                    callback();
                }
            };
            return {
                baseInfo:[],
                location:[],
                channelIdName:'',
                statusList:[],
                operateStatusList:[],
                domicValue: "domicLocation",
                saleDate: '',
                isShowFile: false,
                disabledSingle: true,
                disabledGroup: '是',
                loading: true,
                operationLoading: false,
                importLoading: false,
                loadingExport: true,
                disabled:null,
                drop: false,
                isOrNo:false,
                longTermOrNot:false,
                viewImage: false,
                modalType: 0,
                examineType:null,
                userModalVisible: false,
                registeredProvinceCity:[],
                companyForm: {
                    channelId:'',
                    whetherLicence: '',
                    affiliatedName: '',
                    socUniCrtCode: "",
                    foundedTime: "",
                    transPermitValidity: "",
                    legalPersonName: "",
                    legalPersonTel: "",
                    legalPersonIdcard: "",
                    oprTermValidity: "",
                    operationYears: "",
                    registeredProvince:"",
                    registeredCity:"",
                    registeredAddress:"",
                    termValidity: "",
                    operateVehicles: "",
                    operateStatus: "",
                    longTermOrNot: "",
                    totalApplicationNum:"",
                    monthlyApplicationNum:"",
                    status:"", //修改的状态状态
                    examineRemark:"", // 修改的备注
                    examineReason:"", // 原因
                    type:null,
                    applyTime:'',
                    position: "",
                    domicLocation: [],
                    // 地址信息
                    // addressinfo: [
                    //     {
                    //         detailAddress: [],
                    //
                    //     }
                    // ]
                },
                fileFrom: {
                    productName: ""
                },
                companyFormValidate: {
                    status: [
                        {required: true, message: "请选择审核意见", trigger: "change"},
                        // {validator: validateExamineReason, trigger: "change"}
                    ],
                    monthlyApplicationNum:[
                        {required: true, message: "请填写月申请单数", trigger: "blur"},
                        {required:true,validator: isPositiveInteger, trigger: "blur"}

                    ],
                    totalApplicationNum:[
                        {required: true,message: "请填写总申请单数", trigger: "blur"},
                        {required:true,validator: isPositiveInteger, trigger: "blur"}

                    ]
                },
                submitLoading: false
            };
        },
        methods: {
            // 根据id 去查询数据
            getById() {
                let param={id:this.companyForm.id};
                getAffiliationInfo(param).then(res => {
                    this.operationLoading = false;
                    if (res.code === "0000") {
                        this.isOrNo=res.data.inLibraryOrNot;
                        this.companyForm = res.data;
                        this.companyForm.channelId=this.channelIdName;
                        this.companyForm.operationYears=this.companyForm.operationYears.toString();
                        this.companyForm.registeredCapital=this.companyForm.registeredCapital.toString();
                        this.companyForm.domicLocation = [
                            this.companyForm.registeredProvince, this.companyForm.registeredCity
                        ];
                        if(this.companyForm.longTermOrNot=="1"){
                            this.companyForm.longTermOrNot=true;
                        }else{
                            this.companyForm.longTermOrNot=false;
                        }
                        if(this.companyForm.whetherLicence=="0"){
                            this.companyForm.transPermitValidity="";
                        }
                        if(typeof this.isOrNo == "undefined" || this.isOrNo =="0"){
                            this.isOrNo=false;
                            // this.companyForm.monthlyApplicationNum="";
                            // this.companyForm.totalApplicationNum="";
                        }else if(this.isOrNo==="1"){
                            this.isOrNo=true;
                            this.companyForm.monthlyApplicationNum=this.companyForm.monthlyApplicationNum.toString();
                            this.companyForm.totalApplicationNum=this.companyForm.totalApplicationNum.toString();
                        }
                        this.disabled="disabled";
                        this.companyForm.status="";
                    }
                });
            },
            closeThisTag(){
                this.afs.closeTab(this);
            },
            getLocationData() {
                let param = ""
                param = {
                    level: '1',
                    upperCode: '1'
                };
                getLocation(param).then((res) => {
                    if (res.code == "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        })
                    }
                    this.location.push(...res.data);
                })
            },
            loadData(item, callback) {
                // console.log("是否调用新车")
                item.loading = true;
                getLocation({upperCode: item.value}).then(res => {
                    if (res.code === "0000") {
                        res.data.forEach(function (item) {
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                        item.children = res.data;
                        item.loading = false;
                        callback();
                    }
                })
            },
            Commit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.companyForm.longTermOrNot = this.companyForm.longTermOrNot ===  false ? "0" : "1";
                        this.companyForm.oprTermValidity=this.companyForm.longTermOrNot === "1" ? "" : this.companyForm.oprTermValidity;
                        this.companyForm.registeredProvince=this.companyForm.domicLocation[0];
                        this.companyForm.registeredCity=this.companyForm.domicLocation[1];
                        examineThirdOrNetCar(this.companyForm).then(res => {
                            this.submitLoading = false;
                            if (res.code === "0000") {
                                this.$Message.success("操作成功");
                                this.userModalVisible = false;
                                if(res.data!=""){
                                    let param={id:res.data};
                                    saveThirdOrNetCar(param);
                                }
                                this.afs.closeTab(this);
                                this.$router.push({path: '/affiliationApplyThirdApply'});
                            }
                        });

                    } else {
                        this.$Message.error('请补全信息');
                    }
                })
            },
            getTime() {
                var date = new Date();
                var year = date.getFullYear(); //年 ,从 Date 对象以四位数字返回年份
                var month = date.getMonth() + 1; //月 ,从 Date 对象返回月份 (0 ~ 11) ,date.getMonth()比实际月份少 1 个月
                var day = date.getDate(); //日 ,从 Date 对象返回一个月中的某一天 (1 ~ 31)
                var hours = date.getHours(); //小时 ,返回 Date 对象的小时 (0 ~ 23)
                var minutes = date.getMinutes(); //分钟 ,返回 Date 对象的分钟 (0 ~ 59)
                var seconds = date.getSeconds(); //秒 ,返回 Date 对象的秒数 (0 ~ 59)
                //修改月份格式
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                //修改日期格式
                if (day >= 0 && day <= 9) {
                    day = "0" + day;
                }
                //修改小时格式
                if (hours >= 0 && hours <= 9) {
                    hours = "0" + hours;
                }
                //修改分钟格式
                if (minutes >= 0 && minutes <= 9) {
                    minutes = "0" + minutes;
                }
                //修改秒格式
                if (seconds >= 0 && seconds <= 9) {
                    seconds = "0" + seconds;
                }
                //格式(yyyy-mm-dd hh:mm:ss)
                var currentFormatDate =
                    year +
                    "-" +
                    month +
                    "-" +
                    day +
                    " " +
                    hours +
                    ":" +
                    minutes +
                    ":" +
                    seconds;
                this.companyForm.applyTime = currentFormatDate;
            },
            showPhote(){
                alert("影像资料");
            },
            getStatus() {
                let param = {
                    type: "affiliationExamine"
                };
                getDictDataByType(param.type).then(res => {
                    if (res.code === "0000") {
                        this.statusList = res.data;
                    }
                });
            },
            getOperateStatus() {
                let param = {
                    type: "affiliationOperateStatus"
                };
                getDictDataByType(param.type).then(res => {
                    if (res.code === "0000") {
                        this.operateStatusList = res.data;
                    }
                });
            },
            getBaseInfo() {
                getChannelBaseInfo({status: "00"}).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        this.baseInfo = res.data;
                        getChannelId({}).then(ress => {
                            if (ress.code === "0000") {
                        //let channelId = "4492879251570075204";
                        // let channelId = "4460600613838667776";
                         let channelId = ress.data;
                                for(let i=0;i<this.baseInfo.length;i++){
                                    if(channelId==this.baseInfo[i].id){
                                        this.companyForm.channelId = this.baseInfo[i].id;
                                        this.channelIdName=this.companyForm.channelId;
                                        this.getTime();
                                        this.companyForm.id=this.afs.getPageParams(this).id;
                                        this.getById();
                                    }
                                }
                            }
                        });
                    }
                });
            },
        },
        mounted() {
            this.getLocationData();
            this.getStatus();
            this.getOperateStatus();
            this.getBaseInfo();
        }
    }
</script>

<style scoped>

</style>
